import {
  reqCategoryList,
  reqGetBannerList,
  reqFloorList
} from "@/api";
//state :仓库储存数据的地方
const state = {
  categoryList: [],
  bannerList: [],
  floorList:[]
}
//mutations 修改 state的唯一手段
const mutations = {
  CATEGORYLIST(state, categoryList) {
    state.categoryList  =  categoryList
    },
  GETBANNERLIST(state,res){
    state.bannerList= res
  },
  GETFLOORLIST(state,floorList){
    state.floorList = floorList
  }
}
//action 处理 action 可以书写自己的业务逻辑 也可以处理异步
const actions = {
  //通过api 里面的结果函数调用，向服务器发送请求，获取服务器的数据
  async categoryList({
    commit
  }) {
    let res = await reqCategoryList();
    console.log(res);
    if (res.code == 200) {
      commit("CATEGORYLIST", res.data)
    }
  },
  async getBannerList({
    commit
  }) {
    let result = await reqGetBannerList();
    if (result.code == 200) {
      commit("GETBANNERLIST", result.data)
    }
  },
 async getFloorList({commit}){
   
    let result= await reqFloorList()
    if(result.code ==200){
    //提交mutation
    commit("GETFLOORLIST",result.data)
    }
  }

}
//getters 理解为计算属性 用于简化仓库数据 让组件获取仓库数据更加方便
const getters = {};
//对外暴露Store 类的一个实列
export default ({
  namespaced: true,
  state,
  mutations,
  actions,
  getters
})
